package com.example.springbook.service;

import com.example.springbook.bean.Book;
import com.example.springbook.dao.BookDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookServiceImpl implements BookService{

    @Autowired
    private BookDao bookDao;

    @Override
    public boolean addBook(Book book) {
        boolean flag=false;
        try{ bookDao.addBook(book); flag=true; }catch(Exception e){e.printStackTrace();}
        return flag;
    }

    @Override
    public boolean updateBook(Book book) {
        boolean flag=false;
        try{ bookDao.updateBook(book); flag=true; }catch(Exception e){e.printStackTrace();}
        return flag;
    }
    @Override
    public boolean returnBook(int bookid) {
        boolean flag=false;
        try{ bookDao.returnBook(bookid); flag=true; }catch(Exception e){e.printStackTrace();}
        return flag;
    }

    @Override
    public boolean lendBook(int bookid) {
        boolean flag=false;
        try{ bookDao.lendBook(bookid); flag=true; }catch(Exception e){e.printStackTrace();}
        return flag;
    }
    @Override
    public boolean deleteBook(int bookid) {
        boolean flag=false;
        try{ bookDao.deleteBook(bookid); flag=true; }catch(Exception e){e.printStackTrace();}
        return flag;
    }

    @Override
    public int findSurplus(int bookid) { return bookDao.findSurplus(bookid); }
    @Override
    public List<Book> findByBookName(String bookName) { return bookDao.findByBookName(bookName); }

    @Override
    public List<Book> findBookAll() { return bookDao.findBookAll(); }
}
